﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Runtime.Serialization
{
  public class SerializationFactory<T> : ISerializationFactory
  {
    private Func<Package, T> _deserializer;
    private Action<Package, T> _serializer;

    protected SerializationFactory()
    {

    }

    public SerializationFactory(Func<Package, T> deserializer, Action<Package, T> serializer)
    {
      _serializer = serializer;
      _deserializer = deserializer;
    }

    public virtual void Serialize(Package package, T obj)
    {
      _serializer(package, obj);
    }

    public void ISerializationFactory.Serialize(Package package, object obj)
    {
      Serialize(package, (T)obj);
    }

    public virtual T Deserialize(Package package)
    {
      return _deserializer(package);
    }

    public object ISerializationFactory.Deserialize(Package package)
    {
      return Deserialize(package);
    }
  }
}
